<include file="Common/works/header" />
<include file="Common/works/left_menu" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/pagination.css"/>

  <div class="right">
    <div class="title">我的服务</div>

    <div class="service_list">
      <div class="service_bt"><a href="#" title="添加服务" class="service _add_service" id="grant">添加服务</a></div>
      <div class="table-top"><div class="tab">更新时间</div><div class="tab">服务名称</div><div class="tab">所有API</div><div class="tab">线上API</div><div class="tabr">操作</div></div>
      <!-- 循环 -->
      <foreach name="list" item="value" key="key" >
      <div class="table-foot _raw_service" data-id="{$value.service_id}">
        <!-- <div class="tab">{$value.update_time|date='Y-m-d H:i:s',###}</div> -->
        <div class="tab">{$value.greatest_update_time}</div>
        <div class="tab"><a class="text-left margin-010" href="/apiworks/serviceView?service_id={$value.service_id}" title="{$value.service_name}" target="_blank">{$value.service_name}</a></div>
        <div class="tab">{$value.all_num}</div>
        <div class="tab">{$value.online_num}</div>
        <div class="tabr">
          <div class="inline-flex">
            <a href="/apiworks/apiAdd.html?service_id={$value.service_id}" title="添加API">添加API</a>
            <a href="/apiworks/serviceEdit.html?service_id={$value.service_id}" title="编辑">编辑</a>
            <a href="#" data-id="{$value.service_id}" class="_service_list_del" title="删除">删除</a>
          </div>
        </div>
      </div>
      </foreach>
      <!-- 循环结束 -->
    </div>
    
    <div class="cls"></div>
    <div class="page fr" style="margin-right:20px">{$page}</div>
    <!-- <include file="Common/footer_simple" /> -->
  </div>
</div>
<div id="delBox" class="grantdiv">
  <div class="hz">
    <div class="hztop"><a href="javascript:void(0)" title="关闭窗口" class="close_btn _close_btn" ><img src="__PUBLIC__/home/images/no.png" /></a></div>
    <div class="hzcp">
      <p>该服务下所有未发布的API会一并删除。是否删除该服务?</p>
    </div>
    <div class="mydiv-foot" style=" width:250px; margin:0 auto"><a href="javascript:void(0)" class="smthree fl _close_btn">取消</a><a class="smtwo fr _confirm_btn">确认</a></div>
  </div>
</div>

<div id="unauthBox" class="grantdiv">
  <div class="hz">
    <div class="hztop"><a href="javascript:void(0)" title="关闭窗口" class="close_btn _close_btn" ><img src="__PUBLIC__/home/images/no.png" /></a></div>
    <div class="hzcp">
      <p>请完善个人信息认证后继续操作</p>
    </div>
    <div class="mydiv-foot" style=" width:250px; margin:0 auto"><a href="javascript:void(0)" class="smthree fl _close_btn">先看看</a><a class="smtwo fr _toauth_btn">去认证</a></div>
  </div>
</div>

<input type="hidden" value="{$auth_status}" class="_auth_status"/>
<!--/apiworks/serviceDel.html?service_id={$value.service_id}-->
<include file="Common/delWindow" />
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/home/js/jquery.pagination.min.js"></script>
<script type="text/javascript">
  $(function (){
    //添加服务
    $('._add_service').click(function (){
      var auth_status = $('._auth_status').val();
      if(auth_status==0 || auth_status==3){
        $("#unauthBox").fadeIn("slow");

         $("._toauth_btn").unbind('click').click(function (){
             $("#unauthBox").fadeOut("fast");
            location.href="/apiworks/auth.html";
         });

      }else if (auth_status==2){
        location.href="/apiworks/add.html";
      }else if(auth_status==1){
        show_msg({msg:'认证审核中...',type:'warning'});
      }

    });

    //删除服务操作
    $('._service_list_del').click(function (){
      
      var that = $(this);
      $.ajax({
          url:'/apiworks/ajaxOnlineApiNum.html',
          type:'get',
          dataType:'json',
          async:true,
          data:{'service_id':that.attr('data-id')},
          success:function (req){
            if(req.status==200){
//              console.log(req)
              //return
              num=req.data;
              if(num==0){
            	  delService(that);
//                  location.reload(true);
              }else{
            	  show_msg({msg:'有已上线API,不能删除',type:'error',time:1000});
              }
              return;
            }else{
              show_msg({msg:req.msg,type:'error',time:1000});
              return;
            }
          },
          error:function (){
            show_msg({msg:'系统异常',type:'error',time:1000});
            return;
          }
        });
      
      
    });
    //点击取消，隐藏确认框 
    $("._close_btn").on('click', function () {
		  $("#delBox,#unauthBox").fadeOut("fast");
	  });
  });
  
  
  function delService(that){
	      
	      $("#delBox").fadeIn("slow");

	      $("._confirm_btn").unbind('click').click(function(){
	    	  $("#delBox").fadeOut("fast");
	          $.ajax({
	              url:'/apiworks/ajaxServiceDel.html',
	              type:'get',
	              dataType:'json',
	              async:true,
	              data:{'service_id':that.attr('data-id')},
	              success:function (req){
	                if(req.status==200){
	                  that.parent().parent('._raw_service').remove();
	                  show_msg({msg:req.msg,type:'ok',time:1000});
                      location.reload(true)
	                }else{
	                  show_msg({msg:req.msg,type:'error',time:1000});
	                }
	                return;
	              },
	              error:function (){
	                show_msg({msg:'系统异常',type:'error',time:1000});
	              }
	            });
	      });
  }
  
  
</script>
</body>
</html>
